<?php
/**************************
@Author  : sulwan
@Content : 登陆页面
**************************/
include_once(dirname(__file__).'/../init.php');
$action = trim(_g('action'));
switch($action) {
case login:
	login();
	break;
default:
	showIndex();
}

/*默认执行方法*/
function showIndex() {
	global $config;
	$userInfo = userInfo();
	if(!empty($userInfo)) {
		$url = '/manage/';
		$time = 3;
		$message = '正在进入后台';
		redirect($url,$time,$message);
	}
	include template('login/index.html');
}


/*登录方法*/
function login() {
	global $config;
	$username = trim(_g('username'));
	$userPassword = trim(_g('userPassword'));
	$authNum = strtolower(trim(_g('authNum')));
	$authNumService = Session::Get('picNum');
	if($authNum != $authNumService) {
		$url = '/home/';
		$time = 3;
		$message = '验证码填写错误，请从新填写';
		redirect($url,$time,$message);
	}
	$userInfo = User::checkLogin($username,$userPassword,$fillInfo = false,'username');
	if(!empty($userInfo)) {
		$login = User::login($userInfo);
		$url = 'http://'.$config['web'];
		$time = 2;
		$msg = '登录成功';
		redirect($url,$time,$msg);
	}else{
		$url = '../';
		$time = 2;
		$msg = '账户或密码错误';
		redirect($url,$time,$msg);
	}
}
?>